import java.util.concurrent.atomic.AtomicInteger;

/**
* Created with IntelliJ IDEA.
* Description:
* Date: 2024-08-27
* Time: 9:52
*/

public class CasTest {
    public static AtomicInteger count = new AtomicInteger(0);

    public static void main(String[] args) throws InterruptedException {
        Thread[] threads = new Thread[10];

        for (int i = 0; i < 10; i++) {
            threads[i] = new Thread(() -> {
                for (int j = 0; j < 1000; j++) {
                    //count++;
                    count.getAndIncrement();
                    //++count
                    count.incrementAndGet();
                    //count--
                    count.getAndDecrement();
                    //--count
                    count.decrementAndGet();
                }
            });
        }

        for (Thread thread : threads) {
            thread.start();
        }

        for (Thread thread : threads) {
            thread.join();
        }

        System.out.println("总数" + count);
    }
}
